package com.zyb.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zyb.pojo.Message;
import com.zyb.pojo.User;
import com.zyb.service.MessageService;

@Controller
@RequestMapping("user")
public class UserController {

	@Resource
	private MessageService messageService;
	
	@RequestMapping("/message")
	public @ResponseBody String message(String message,HttpServletRequest request) {
		HttpSession session = request.getSession();
		String result = messageService.insertMessage(message,(User)session.getAttribute("user"));
		return result;
	}
	
	@RequestMapping("/messageList")
	public @ResponseBody String messageList() {
		List<Message> messages = messageService.findMessages();
		System.out.println(messages);
		JSONArray jsonarray  = new JSONArray();
		String json = JSONArray.toJSONString(messages);
		System.out.println(json);
		return json;
	}
}
